package cn.hicard.risk.dao.limit.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.hicard.core.Page;
import cn.hicard.core.PageResult;
import cn.hicard.core.Where;
import cn.hicard.risk.dao.BaseDao;
import cn.hicard.risk.dao.limit.LimitFreezeinfoDao;
import cn.hicard.risk.entity.LimitFreezeinfo;


@Repository
public class LimitFreezeinfoDaoImpl extends BaseDao<LimitFreezeinfo> implements LimitFreezeinfoDao{

	@Override
	public LimitFreezeinfo findByMid(String mid) throws Exception {
		
		String hql = "FROM LimitFreezeinfo WHERE mid = ?";
		LimitFreezeinfo info = null;
		List<LimitFreezeinfo> list = super.findByHql(hql, mid);
	    
		if(list!=null){
			info = list.get(0);
		}
		return info;
	}
	
	public PageResult<LimitFreezeinfo> findPage(Where where,Page page) throws Exception {
		
		String hqlData = " FROM LimitFreezeinfo WHERE 1=1 ";
		String hqlCount  = "SELECT COUNT(*) FROM LimitFreezeinfo WHERE 1=1 ";
	
		PageResult<LimitFreezeinfo> result = new PageResult<LimitFreezeinfo>();

		hqlData += where.queryString();
		hqlData += " ORDER BY freezetime DESC";
		hqlCount+=where.queryString();		
		int ii = super.findCountByHql(hqlCount, where.getParams());
		List<LimitFreezeinfo> list = super.findByHqlPage(hqlData, page, where.getParams());
		result.setResultCount(ii);
		result.setDataList(list);
		
		return result;
	
	}
	
	@Override
	/**
	 * 获取报表信息
	 */
	public List<LimitFreezeinfo> findReportList(Where where) throws Exception {
		
		String hqlData = " FROM LimitFreezeinfo WHERE 1=1 " + where.queryString()+ " ORDER BY freezetime DESC";
		List<LimitFreezeinfo> list = super.findByHql(hqlData, where.getParams());
		return list;
			
	}
	
	/**
	 * 获取上一个工作日商户的冻结信息
	 * @param where
	 * @return
	 * @throws Exception
	 */
    public LimitFreezeinfo findPreFreezeInfo(Where where) throws Exception {
	    LimitFreezeinfo freezeInfo = null;
		String hqlData = " FROM LimitFreezeinfo WHERE 1=1 " + where.queryString()+ " ORDER BY pk_freezeinfo DESC";
		List<LimitFreezeinfo> list = super.findByHql(hqlData, where.getParams());
		
		if(list!=null&&list.size()!=0){
			freezeInfo = list.get(0);
		}
		return freezeInfo;
			
	}
	

	@Override
	public void updateFreezeinfo(LimitFreezeinfo info) throws Exception {
		super.update(info);
	}
  
	public void save(LimitFreezeinfo info)throws Exception{
		super.save(info);
	}

	
	
}
